<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<ui:composition template="template.xhtml">
	<ui:define name="content">

	<h:form>
		<h2>Gestione Voli</h2>

		<p>
			Vuoi inserire un nuovo volo? <p:button outcome="newFlight" value="Crea nuovo elemento" />
		</p>
	</h:form>
	 
	 <h:form>
		<p:dataTable var="el" value="#{flightBean.allFlights}"   
	           emptyMessage="Nessun elemento corrisponde ai criteri di ricerca.">  
	 	
	       <p:column   
	               headerText="Partenza"
	               filterMatchMode="contains">  
	           <h:outputText value="#{el.airport1.name} (#{el.airport1.location.name})" />  
	       </p:column> 
	       
	       <p:column   
	               headerText="Data e ora partenza"
	               filterMatchMode="contains">  
	           <h:outputText value="#{el.departureTime}">
	           		<f:convertDateTime pattern="dd.MM.yyyy HH:mm" />
	           </h:outputText>
	       </p:column>  
	       
	       <p:column   
	               headerText="Arrivo"
	               filterMatchMode="contains">  
	           <h:outputText value="#{el.airport2.name} (#{el.airport2.location.name})" />  
	       </p:column> 
	       
	       <p:column   
	               headerText="Data e ora arrivo"
	               filterMatchMode="contains">  
	           <h:outputText value="#{el.landingTime}"> 
	           		<f:convertDateTime pattern="dd.MM.yyyy HH:mm" />
	           </h:outputText>
	       </p:column> 
	       
	       <p:column   
	               headerText="Compagnia"
	               filterMatchMode="contains">  
	           <h:outputText value="#{el.company}" />  
	       </p:column> 
	       
	       <p:column  
	               headerText="Prezzo"
	               filterMatchMode="contains">  
	           <h:outputText value="#{el.price}" />  
	       </p:column> 
	       
	       <p:column>  
	           <center>

		           <p:button outcome="editFlight" value="Modifica">  
						<f:param name="elementId" value="#{el.id}" />  
				   </p:button>
				   <p:commandButton action="#{flightBean.deleteFlight(el.id)}" value="Elimina" />
			   </center>
	       </p:column>
	   	</p:dataTable>
	</h:form>
	
	<p:messages showDetail="true" autoUpdate="true" closable="true" />

	</ui:define>
</ui:composition>
</html>